<template>
  <!--ASN明细-->
  <div id="AsnDetails">
    <v-details :detailData="data.detailData"
               :inputConfig="inputConfig"
               :rules="rules"
               @pop="setdata"></v-details>
  </div>
</template>

<script>

import details from 'commons/Detail'
import baseMixin from "@/mixins/BaseMixin";

export default {
  name: "AsnDetails",
  mixins: [baseMixin],
  props: {
    data: {
      type: Object
    }
  },
  data () {
    return {
      rules: {},
      addflag: false
    }
  },
  computed: {
    inputConfig () {
      return [
        [
          {
            type: "input",
            label: this.$t('outbound.userlinenumber'),
            disabled: true,
            props: "gatherlinenumber",
          },
          {
            type: "table",
            label: this.$t('out.orderkey'),
            props: "orderkey",
            tableConfig: [
              {
                label: this.$t('out.orderkey'),
                prop: "orderkey",
                input: "input",
              },
              {
                label: this.$t('out.wavekey'),
                prop: "wavekey",
                input: "input",
              },
              {
                label: this.$t('config.shipper'),
                prop: "storerkey",
                input: "input",
              }
            ],
            url: `/gatherQueryOrderkey/?/undefined`
          },

        ]
      ]
    }
  },
  methods: {
    setdata (data, id, close) {
      this.data.detailData.orderkey = data.orderkey;
      if (data.wavekey) {
        this.data.detailData.wavekey = data.wavekey;
      } else {
        this.data.detailData.wavekey = " ";
      }
      this.data.detailData.storerkey = data.storerkey;
      close(false);
    }
  },
  async mounted () {
    if (Object.keys(this.$store.state.skip).length !== 0) {
      let data = this.$store.state.skip;
      if (data.newFlag) {
        this.addflag = false;
      } else {
        this.addflag = true;
      }
    } else if (this.$store.state.newFlag) {
      try {
        let res = await this.$api.get(`/queryGatherMaxLine/${this.$store.state.routeId}`)
        
          this.data.detailData.gatherlinenumber = res.data.seq;
          this.data.detailData.whseid = res.data.whseid;
        
      } catch (e) {
        this.$message.error(e);
      }
      this.addflag = false;
    } else {
      this.addflag = true;
    }

  },
  watch: {
    "$parent.$parent.$refs.detail.detailData.carrierkey": {
      handler (data) {
        this.inputConfig[0].forEach(item => {
          if (item.props == "orderkey") {
            item.url = `/gatherQueryOrderkey/?/${data}`
          }
        })
      },
      deep: true,
      immediate: true,
    },
  },
  components: {
    'v-details': details
  }
}
</script>

<style scoped>
</style>
